import { detectDevice, debounce } from './utils';

/**
 * 设计稿设计尺寸，与vite.config.js保持一致
 */
const DESIGN_SCALE = 375;
const DESIGN_SCALE_PC = 1920;

/**
 * 用于行间样式转换，将px转换为rem
 * @param px 需要转换的px值
 * @returns 转换好的rem字符串
 */
export function $px(px: string | number) {
    px = String(px);
    if (/%/gi.test(px)) return px;

    return parseFloat(px) / (DESIGN_SCALE / 10) + 'rem';
}

export function setPcRem() {
    const IsPC = detectDevice() === 'pc';
    if (!IsPC) return;
    document.documentElement.style.fontSize = `${((window.innerWidth / DESIGN_SCALE_PC) * DESIGN_SCALE) / 10}px`;
}

export function setAppRem() {
    const IsAPP = detectDevice() != 'pc';
    if (!IsAPP) return;

    // console.log(window.innerWidth, 'window.innerWidth');

    document.documentElement.style.fontSize = `${((window.innerWidth / DESIGN_SCALE) * DESIGN_SCALE) / 10}px`;
}
